#include <glib.h>

static void _queue_foreach_func(gpointer data, gpointer       user_data)
{
    g_print("user_data:%s, data:%d \n", (gchar *)user_data, GPOINTER_TO_INT(data));
}

gint main(gint argc, gchar **argv)
{
    GQueue *q = NULL;
    GList *l = NULL;

    q = g_queue_new();

    g_queue_push_tail(q, GINT_TO_POINTER(10));
    g_queue_push_tail(q, GINT_TO_POINTER(20));
    g_queue_push_tail(q, GINT_TO_POINTER(30));
    // result: 10-20-30

    g_queue_foreach(q, _queue_foreach_func, "Queue-push");

    // find GList
    l = g_queue_find(q, GINT_TO_POINTER(20));

    g_queue_insert_before(q, l, GINT_TO_POINTER(15));
    g_queue_insert_after(q, l, GINT_TO_POINTER(25));
    // result: 10-15-20-25-30

    g_queue_foreach(q, _queue_foreach_func, "Queue-after-insert");

    g_queue_free(q);

    return 0;
}